<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>添加/修改手续费配置</title>
<%@ include file="/view/common/tags.jsp"%>
<link rel="stylesheet" href="//res.layui.com/layui/dist/css/layui.css?t=1515376178709" media="all">
<style type="text/css">
    .fromDiv{padding-right: 10px;height: 45px;}
</style>
</head>
<body>
	<div class="well well_p" style="padding-top: 15px;">
		<sk:form method="post" cssClass="form-horizontal" id="saveAndUpdateFrom" target="_parent" action="">
			<input type="hidden" id="rowId" name="rowId" value='<%=request.getParameter("rowId")%>'/>
			<input type="hidden" id="isReCommit" value="0">
			<input type="hidden" id="token" name="token" value="">
			<input type="hidden" id="feePackageName" name="feePackageName" value="">
			<input type="hidden" id="gameName" name="gameName" value="">
			<input type="hidden" id="areaName" name="areaName" value="">
			<input type="hidden" id="serverName" name="serverName" value="">
			<input type="hidden" name="typeName" id="typeName" value=""/>
			<input type="hidden" id="goodsBigName" name="goodsBigName" value="">
			<input type="hidden" id="goodsSmallName" name="goodsSmallName" value="">
			<input type="hidden" id="tradeName" name="tradeName" value="">
			<div class="form-group fromDiv" style="display: none;">
  				<label class="col-xs-2 text-right">手续费套餐:</label>
  				<div class="col-xs-2">
  					<sk:select cssClass="form-control select" id="feePackageId" name="feePackageId" value="">
  						<option value="9">基础套餐</option>
  					</sk:select>
  				</div>
            </div>
            <div class="form-group fromDiv" >
				<label class="col-xs-2 text-right"><span class="layui-badge-dot"></span> 游戏名称：</label>
				<div class="col-xs-2">
					<sk:select cssClass="form-control select" id="gameId" name="gameId" value="" requiredInit="true" ajaxURL="${userInfoV1}/baseGame/gameSelect?wm[DEL_FLAG]=1" onchange="TagUtil.fillOptions('gameId');">
						<option value="">请选择</option>
					</sk:select>
				</div>
				<label class="col-xs-2 text-right">区：</label>
				<div class="col-xs-2">
					<sk:select cssClass="form-control select" id="areaId" name="areaId" value="" ajaxURL="${userInfoV1}/baseArea/select?wm[DEL_FLAG]=1" parentCascadedSelect="gameId" parentParamName="gameId" onchange="TagUtil.fillOptions('areaId');" >
						<option value="">请选择</option>
					</sk:select>
				</div>
				<label class="col-xs-2 text-right">服：</label>
				<div class="col-xs-2">
					<sk:select cssClass="form-control select" id="serverId" name="serverId" value="" ajaxURL="${userInfoV1}/baseServer/select?wm[DEL_FLAG]=1" parentCascadedSelect="areaId" parentParamName="areaId">
						<option value="">请选择</option>
					</sk:select>
				</div>
			</div>
            <div class="form-group fromDiv" >
                <label class="col-xs-2 text-right" style="margin-left: -10px;"><span class="layui-badge-dot"></span> 交易类型:</label>
                <div class="col-xs-2" style="margin-left: 10px;">
                    <sk:select cssClass="form-control select" id="tradeId" name="tradeId" value="" parentCascadedSelect="gameId" parentParamName="gameId" requiredInit="true" ajaxURL="${tradeV1}/tradeState/gameTradeTypeDictList">
                        <option value="">请选择</option>
                    </sk:select>
                </div>
			</div>
            <div class="form-group fromDiv" >
                <label class="col-xs-2 text-right"><span class="layui-badge-dot"></span> 商品基类：</label>
                <div class="col-xs-2">
                    <sk:select cssClass="form-control select" id="typeFlag" name="typeFlag" value="" parentCascadedSelect="gameId" parentParamName="wm[GAME_ID]" ajaxURL="${userInfoV1}/gameGoodsType/baseTypeSelect?1=1" onchange="setAjxaUrl('goodsBigId', 'gameId'); TagUtil.fillOptions('typeFlag');">
                        <option value="">请选择</option>
                    </sk:select>
                </div>
				<label class="col-xs-2 text-right"><span class="layui-badge-dot"></span> 商品大类：</label>
				<div class="col-xs-2">
					<sk:select cssClass="form-control select" id ="goodsBigId" name="goodsBigId" value="" parentCascadedSelect="typeFlag" parentParamName="wm[TYPE_FLAG]" ajaxURL="${userInfoV1}/gameGoodsType/typeSelect?1=1" onchange="setAjxaUrl('goodsSmallId', 'gameId'); TagUtil.fillOptions('goodsBigId')">
						<option value="">请选择</option>
					</sk:select>
				</div>
				<label class="col-xs-2 text-right">商品小类:</label>
				<div class="col-xs-2">
					<sk:select cssClass="form-control select" id="goodsSmallId" name="goodsSmallId" value="" parentCascadedSelect="goodsBigId" parentParamName="wm[PARENT_ID]" ajaxURL="${userInfoV1}/gameGoodsType/smallTypeSelect?1=1">
						<option value="">请选择</option>
					</sk:select>
				</div>
			</div>
                <hr/>
			<div class="form-group fromDiv">
				<label class="col-xs-2 text-right">最低发布额:</label>
				<div class="col-xs-2">
					<input type="text" class="form-control" name="minSalePrice" id="minSalePrice" value="1"  placeholder="最低发布额">
				</div>
				<label class="col-xs-2 text-right">最低手续费费率:</label>
				<div class="col-xs-2">
					<input type="text" class="form-control" name="minFeeRate" id="minFeeRate" value="0"  placeholder="最低费率">
				</div>
				<label class="col-xs-2 text-right">最低附加金额:</label>
				<div class="col-xs-2">
					<input type="text" class="form-control" name="minFee" id="minFee" value="0"  placeholder="附加金额">
				</div>
			</div>
			<div class="form-group fromDiv">
				<label class="col-xs-2 text-right">中间发布额:</label>
				<div class="col-xs-2">
					<input type="text" class="form-control" name="midSalePrice" id="midSalePrice" value="5000"  placeholder="中间发布额">
				</div>
				<label class="col-xs-2 text-right">中间手续费费率:</label>
				<div class="col-xs-2">
					<input type="text" class="form-control" name="midFeeRate" id="midFeeRate" value="0"  placeholder="中间费率">
				</div>
				<label class="col-xs-2 text-right">中间附加金额:</label>
				<div class="col-xs-2">
					<input type="text" class="form-control" name="midFeeAppend" id="midFeeAppend" value="0"  placeholder="附加金额">
				</div>
			</div>
			<div class="form-group fromDiv">
				<label class="col-xs-2 text-right">最高发布额:</label>
				<div class="col-xs-2">
					<input type="text" class="form-control" name="maxSalePrice" id="maxSalePrice" value="9999999"  placeholder="最高发布额">
				</div>
				<label class="col-xs-2 text-right">最高手续费:</label>
				<div class="col-xs-2">
					<input type="text" class="form-control" name="maxFee" id="maxFee" value="100"  placeholder="最高手续费">
				</div>
			</div>
		</sk:form>
	</div>
</body>
<%@ include file="/view/common/footer.jsp"%>
<script>
    var configId = $("#rowId").val();//手续费配置ID
    $(function(){
        //后台登录用户token
        $("#token").val(sessionStorage.getItem("token"));
        //修改手续费配置时获取数据
        if(configId > 0){
            $.ajax({
                url: "${tradeV1}/tradeBasePackageFeeDetail/getPackageFeeDetailInfo",
                type: "post",
                cache: false,
                data:{"rowId":configId},
                dataType:"json",
                async:false,
                success: function(data) {
                    if (data == null) {
                        return;
                    }
                    $("#feePackageId").val(data.feePackageId);
                    $("#feePackageName").val(data.feePackageName);
                    $("#gameId").val(data.gameId);
                    $("#gameName").val(data.gameName);
                    TagUtil.fillOptions('gameId');
                    $("#areaId").val(data.areaId);
                    $("#areaName").val(data.areaName);
                    TagUtil.fillOptions('areaId');
                    $("#serverId").val(data.serverId);
                    $("#serverName").val(data.serverName);
                    $("#typeFlag").val(data.typeFlag);
                    $("#typeName").val(data.typeName);
                    setAjxaUrl('goodsBigId', 'gameId');
                    TagUtil.fillOptions('typeFlag');
                    $("#goodsBigId").val(data.goodsBigId);
                    $("#goodsBigName").val(data.goodsBigName);
                    setAjxaUrl('goodsSmallId', 'gameId');
                    TagUtil.fillOptions('goodsBigId');
                    $("#goodsSmallId").val(data.goodsSmallId);
                    $("#goodsSmallName").val(data.goodsSmallName);
                    $("#tradeId").val(data.tradeId);
                    $("#tradeName").val(data.tradeName);
                    $("#minSalePrice").val(data.minSalePrice);
                    $("#minFee").val(data.minFee);
                    $("#minFeeRate").val(data.minFeeRate);
                    $("#midSalePrice").val(data.midSalePrice);
                    $("#midFeeAppend").val(data.midFeeAppend);
                    $("#midFeeRate").val(data.midFeeRate);
                    $("#maxSalePrice").val(data.maxSalePrice);
                    $("#maxFee").val(data.maxFee);
                }
            });
        }
    });
    var err = {'1':'添加','2':'修改'};
    var action = {'1': '${tradeV1}/tradeBasePackageFeeDetail/save','2': '${tradeV1}/tradeBasePackageFeeDetail/update'};
    function add(){
        var rowId = $('#rowId').val();
        var opera;
        if (!CheckUtil.isNotNull(rowId) || rowId <= 0) {
            opera = 1;//添加
        } else {
            opera = 2;//修改
        }
        var feePackageId = $("#feePackageId").val();
        if (!CheckUtil.isNotNull(feePackageId)) {
            layer.msg("请选择手续费套餐!");
            return;
        }
        var gameId = $("#gameId").val();
        if (!CheckUtil.isNotNull(gameId)) {
            layer.msg("请选择游戏!");
            return;
        }
        var areaId = $("#areaId").val();
        var serverId = $("#serverId").val();
        var typeFlag = $("#typeFlag").val();
        var goodsBigId = $("#goodsBigId").val();
        var goodsSmallId = $("#goodsSmallId").val();
        if (!CheckUtil.isNotNull(typeFlag)) {
            layer.msg("请选择商品基类!");
            return;
        }
        if (!CheckUtil.isNotNull(goodsBigId)) {
            layer.msg("请选择商品大类!");
            return;
        }
        var tradeId = $("#tradeId").val();
        if (!CheckUtil.isNotNull(tradeId)) {
            layer.msg("请选择交易类型!");
            return;
        }
        var minSalePrice = $("#minSalePrice").val();
        if (!CheckUtil.isNotNull(minSalePrice) || (!CheckUtil.isInt(minSalePrice, "+") && !CheckUtil.isFloat(minSalePrice, "+")) || parseInt(minSalePrice) ==0) {
            layer.msg("请输入正确的最低发布额!");
            return;
        }
        var minFee = $("#minFee").val();
        if (!CheckUtil.isNotNull(minFee) || (!CheckUtil.isInt(minFee, "+") && !CheckUtil.isFloat(minFee, "+"))) {
            layer.msg("请输入正确的最低手续费金额!");
            return;
        }
        var minFeeRate = $("#minFeeRate").val();
        if (!CheckUtil.isNotNull(minFeeRate) || (!CheckUtil.isInt(minFeeRate, "+") && !CheckUtil.isFloat(minFeeRate, "+")) || parseInt(minFeeRate) >= 1) {
            layer.msg("请输入正确的最低手续费费率!");
            return;
        }
        var midSalePrice = $("#midSalePrice").val();
        if (!CheckUtil.isNotNull(midSalePrice) || (!CheckUtil.isInt(midSalePrice, "+") && !CheckUtil.isFloat(midSalePrice, "+")) || parseInt(midSalePrice) ==0) {
            layer.msg("请输入正确的中间发布额!");
            return;
        }
        var midFeeAppend = $("#midFeeAppend").val();
        if (!CheckUtil.isNotNull(midFeeAppend) || (!CheckUtil.isInt(midFeeAppend, "+") && !CheckUtil.isFloat(midFeeAppend, "+"))) {
            layer.msg("请输入正确的中间手续费金额!");
            return;
        }
        var midFeeRate = $("#midFeeRate").val();
        if (!CheckUtil.isNotNull(midFeeRate) || (!CheckUtil.isInt(midFeeRate, "+") && !CheckUtil.isFloat(midFeeRate, "+")) || parseInt(midFeeRate) >= 1) {
            layer.msg("请输入正确的中间手续费费率!");
            return;
        }
        var maxSalePrice = $("#maxSalePrice").val();
        if (!CheckUtil.isNotNull(maxSalePrice) || (!CheckUtil.isInt(maxSalePrice, "+") && !CheckUtil.isFloat(maxSalePrice, "+")) || parseInt(maxSalePrice) ==0) {
            layer.msg("请输入正确的最高发布额!");
            return;
        }
        var maxFee = $("#maxFee").val();
        if (!CheckUtil.isNotNull(maxFee) || (!CheckUtil.isInt(maxFee, "+") && !CheckUtil.isFloat(maxFee, "+"))) {
            layer.msg("请输入正确的最高手续费!");
            return;
        }
        if ($("#isReCommit").val() == 0) {
            $("#isReCommit").val(1);
            //loading层
            var index = layer.load(0, {
                shade: [0.1,'#fff'] //0.1透明度的白色背景
            });
            $("#feePackageName").val($("#feePackageId option:selected").text());
            $("#gameName").val($("#gameId option:selected").text());
            if (CheckUtil.isNotNull(areaId)) {
                $("#areaName").val($("#areaId option:selected").text());
            } else {
                $("#areaName").val("");
            }
            if (CheckUtil.isNotNull(serverId)) {
                $("#serverName").val($("#serverId option:selected").text());
            } else {
                $("#serverName").val("");
            }
            $("#typeName").val($("#typeFlag option:selected").text());
            $("#goodsBigName").val($("#goodsBigId option:selected").text());
            if (CheckUtil.isNotNull(goodsSmallId)) {
                $("#goodsSmallName").val($("#goodsSmallId option:selected").text());
            } else {
                $("#goodsSmallName").val("");
            }
            $("#tradeName").val($("#tradeId option:selected").text());
            $.ajax({
                url: action[opera],
                type: "post",
                cache: false,
                data: new FormData($("#saveAndUpdateFrom")[0]),
                dataType:"json",
                processData: false,
                contentType: false,
                async:false,
                success: function(data) {
                    layer.close(index);
                    if(data.code == 0){
                        parent.layer.msg("添加成功！");
                    } else if(data.code == 1){
                        parent.layer.msg("修改成功！");
                    } else if(data.code == "-2"){
                        parent.window.location.href="${sysManagerV1}/";
                    } else {
                        parent.layer.msg(data.message);
                        $("#isReCommit").val(0);
                    }
                    if(data.code >= 0){
                        parent.findData();
                        parent.layer.close(parent.tableIndex);
                    }
                }
            });
        }
    }

    //给目标select的ajaxURL 加参数
    function setAjxaUrl(keyId, valueId){
        var gameId = $("#" + valueId).find("option:selected").val();
        var ajaxURL = $("#" + keyId).attr("ajaxURL");
        if(ajaxURL.indexOf("GAME_ID") < 0){
            ajaxURL += "&wm[GAME_ID]=" + gameId;
        } else {
            var valueTemp = ajaxURL.substring(ajaxURL.indexOf("wm[GAME_ID]="));
            if(valueTemp.indexOf("&") >= 0){
                valueTemp = valueTemp.substr(valueTemp.indexOf("=") + 1, valueTemp.indexOf("&"));
            }
            ajaxURL = ajaxURL.replace(valueTemp, "wm[GAME_ID]=" + gameId);
        }
        $("#" + keyId).attr("ajaxURL", ajaxURL);
    }
</script>
</html>